﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace Presentation
{
	public partial class RatingControl : UserControl
	{
		public int Value = 0;
		public int RatingValue
		{
			get { return Value; }
			set { Value = value; }
		}
		public RatingControl()
		{
			InitializeComponent();
		}

		public void SetRating(int v)
		{
			Value = v;
			switch (v)
			{
				case 1:
					radioStarRating1.Checked = true;
					break;
				case 2:
					radioStarRating2.Checked = true;
					break;
				case 3:
					radioStarRating3.Checked = true;
					break;
				case 4:
					radioStarRating4.Checked = true;
					break;
				case 5:
					radioStarRating5.Checked = true;
					break;
				case 0:
				default:
					radioStarRating1.Checked = false;
					radioStarRating2.Checked = false;
					radioStarRating3.Checked = false;
					radioStarRating4.Checked = false;
					radioStarRating5.Checked = false;
					break;
			}
		}

		private void RatingControl_Load(object sender, EventArgs e)
		{
			switch (Value)
			{
				case 1:
					radioStarRating1.Checked = true;
					break;
				case 2:
					radioStarRating2.Checked = true;
					break;
				case 3:
					radioStarRating3.Checked = true;
					break;
				case 4:
					radioStarRating4.Checked = true;
					break;
				case 5:
					radioStarRating5.Checked = true;
					break;
				case 0:
				default:
					radioStarRating1.Checked = false;
					radioStarRating2.Checked = false;
					radioStarRating3.Checked = false;
					radioStarRating4.Checked = false;
					radioStarRating5.Checked = false;
					break;
			}
		}

        private void radioStarRating0_CheckedChanged(object sender, EventArgs e)
        {
            if (radioStarRating0.Checked)
            {
                Value = 0;
                radioStarRating1.Image = Properties.Resources.star_grey;
                radioStarRating2.Image = Properties.Resources.star_grey;
                radioStarRating3.Image = Properties.Resources.star_grey;
                radioStarRating4.Image = Properties.Resources.star_grey;
                radioStarRating5.Image = Properties.Resources.star_grey;
            }
        }

		private void radioStar1_CheckedChanged(object sender, EventArgs e)
		{
			if (radioStarRating1.Checked)
			{
				Value = 1;
				radioStarRating1.Image = Properties.Resources.star;
				radioStarRating2.Image = Properties.Resources.star_grey;
				radioStarRating3.Image = Properties.Resources.star_grey;
				radioStarRating4.Image = Properties.Resources.star_grey;
				radioStarRating5.Image = Properties.Resources.star_grey;
			}
			else
			{
				radioStarRating1.Image = Properties.Resources.star_grey;
				radioStarRating2.Image = Properties.Resources.star_grey;
				radioStarRating3.Image = Properties.Resources.star_grey;
				radioStarRating4.Image = Properties.Resources.star_grey;
				radioStarRating5.Image = Properties.Resources.star_grey;
			}
		}

		private void radioStar2_CheckedChanged(object sender, EventArgs e)
		{
			if (radioStarRating2.Checked)
			{
				Value = 2;
				radioStarRating1.Image = Properties.Resources.star;
				radioStarRating2.Image = Properties.Resources.star;
				radioStarRating3.Image = Properties.Resources.star_grey;
				radioStarRating4.Image = Properties.Resources.star_grey;
				radioStarRating5.Image = Properties.Resources.star_grey;
			}
			else
			{
				radioStarRating1.Image = Properties.Resources.star;
				radioStarRating2.Image = Properties.Resources.star_grey;
				radioStarRating3.Image = Properties.Resources.star_grey;
				radioStarRating4.Image = Properties.Resources.star_grey;
				radioStarRating5.Image = Properties.Resources.star_grey;
			}
		}

		private void radioStar3_CheckedChanged(object sender, EventArgs e)
		{
			if (radioStarRating3.Checked)
			{
				Value = 3;
				radioStarRating1.Image = Properties.Resources.star;
				radioStarRating2.Image = Properties.Resources.star;
				radioStarRating3.Image = Properties.Resources.star;
				radioStarRating4.Image = Properties.Resources.star_grey;
				radioStarRating5.Image = Properties.Resources.star_grey;
			}
			else
			{
				radioStarRating1.Image = Properties.Resources.star;
				radioStarRating2.Image = Properties.Resources.star;
				radioStarRating3.Image = Properties.Resources.star_grey;
				radioStarRating4.Image = Properties.Resources.star_grey;
				radioStarRating5.Image = Properties.Resources.star_grey;
			}
		}

		private void radioStar4_CheckedChanged(object sender, EventArgs e)
		{
			if (radioStarRating4.Checked)
			{
				Value = 4;
				radioStarRating1.Image = Properties.Resources.star;
				radioStarRating2.Image = Properties.Resources.star;
				radioStarRating3.Image = Properties.Resources.star;
				radioStarRating4.Image = Properties.Resources.star;
				radioStarRating5.Image = Properties.Resources.star_grey;
			}
			else
			{
				radioStarRating1.Image = Properties.Resources.star;
				radioStarRating2.Image = Properties.Resources.star;
				radioStarRating3.Image = Properties.Resources.star;
				radioStarRating4.Image = Properties.Resources.star_grey;
				radioStarRating5.Image = Properties.Resources.star_grey;
			}
		}

		private void radioStar5_CheckedChanged(object sender, EventArgs e)
		{
			if (radioStarRating5.Checked)
			{
				Value = 5;
				radioStarRating1.Image = Properties.Resources.star;
				radioStarRating2.Image = Properties.Resources.star;
				radioStarRating3.Image = Properties.Resources.star;
				radioStarRating4.Image = Properties.Resources.star;
				radioStarRating5.Image = Properties.Resources.star;
			}
			else
			{
				radioStarRating1.Image = Properties.Resources.star;
				radioStarRating2.Image = Properties.Resources.star;
				radioStarRating3.Image = Properties.Resources.star;
				radioStarRating4.Image = Properties.Resources.star;
				radioStarRating5.Image = Properties.Resources.star_grey;
			}
		}
	}
}